home *** CD-ROM | disk | FTP | other *** search
- class DiegoWorld implements smashing.World
- {
- var location;
- var oBuildings;
- var oCitizens;
- var oGerms;
- var oPlayer;
- var mcDraw;
- var mcGround;
- var backbg;
- var lives;
- var level;
- var score;
- var cTimeRatio;
- var nDistRatio;
- var aCritters;
- var nTime;
- var moveView;
- var endCheck;
- var aCritterList;
- var aPlacement;
- var howFar;
- static var target;
- var nFullTime = 185;
- var cTime = 0;
- var startTime = 0;
- var nTimeDec = 0;
- var nLowerTimeLimit = 45;
- var nDist = 15000;
- var germReq = 10;
- var timeBonus = 10;
- var playerOffset = 100;
- var nPanic = 0.065;
- var totalCritters = 5;
- var cIdle = 0;
- var nIdle = 5;
- function DiegoWorld(loc)
- {
- DiegoWorld.target = this;
- this.location = loc;
- this.oBuildings = new BuildingHandler(this.location.mcBuildingHolder);
- this.oBuildings.oWorld = this;
- this.oCitizens = new CitizenHandler(this.location.mcCitizens);
- this.oCitizens.oBuildings = this.oBuildings;
- this.oGerms = new GermHandler(this.location.mcGermHolder);
- this.oBuildings.oGerms = this.oGerms;
- this.oPlayer = this.location.mcPlayer;
- this.oPlayer.setBuilding(this.oBuildings,this.oCitizens,this.oGerms);
- this.oPlayer.setShadow(this.location.mcShadow);
- this.oPlayer.oWorld = this;
- this.oPlayer.camera = loc.mcCamera;
- this.mcDraw = loc.mcDraw;
- this.mcGround = loc.mcGround;
- this.backbg = loc.backbg;
- smashing.Menu.watchProp(this,"score","text");
- smashing.Menu.watchProp(this,"cTimeRatio","frameMeter");
- this.lives = 3;
- this.level = 1;
- this.score = 0;
- this.cTimeRatio = 0;
- this.nDistRatio = 0;
- this.aCritters = ["jaguar","marmoset","butterfly","macaw","frog","anaconda","kinkajou","sloth"];
- }
- function onEnter()
- {
- }
- function onExit()
- {
- }
- function onPlay()
- {
- }
- function onPause()
- {
- }
- function update(nElapsed)
- {
- if(nElapsed > 0.06)
- {
- nElapsed = 0.06;
- }
- this.cTime += nElapsed;
- this.cTimeRatio = 1 - this.cTime / this.nTime;
- this.mcDraw.clear();
- this.oCitizens.setRatio(0);
- this.oCitizens.update(nElapsed);
- this.oGerms.update(nElapsed);
- this.oPlayer.update(nElapsed);
- this.moveView(nElapsed);
- this.nDistRatio = smashing.Viewport.x / this.nDist;
- this.endCheck();
- this.oPlayer.render();
- this.oGerms.render();
- this.oCitizens.render();
- this.oBuildings.render();
- this.mcGround.render();
- updateAfterEvent();
- }
- function newGame()
- {
- this.startLevel();
- this.level = 1;
- this.score = 0;
- }
- function startLevel()
- {
- this.backbg.gotoAndStop((this.level - 1) % 3 + 1);
- this.aCritterList = smashing.Misc.rndArray(this.aCritters);
- _global.mcRoot.mcMenu.setCrittersReq(this.aCritterList);
- var _loc4_ = -1;
- var _loc3_ = 0;
- while(_loc3_ < 5)
- {
- if(this.aCritterList[_loc3_] == "sloth")
- {
- _loc4_ = _loc3_;
- break;
- }
- _loc3_ = _loc3_ + 1;
- }
- if(_loc4_ == -1)
- {
- _loc4_ = Math.floor(Math.random() * 5);
- }
- var _loc5_ = [1,1,0,0];
- _loc5_ = smashing.Misc.rndArray(_loc5_);
- this.aPlacement = [];
- _loc3_ = 0;
- while(_loc3_ < 5)
- {
- if(_loc3_ == _loc4_)
- {
- this.aPlacement.push(2);
- }
- else
- {
- this.aPlacement.push(_loc5_.pop());
- }
- _loc3_ = _loc3_ + 1;
- }
- this.location.bg.gotoAndStop((this.level - 1) % 3 + 1);
- this.location.street.gotoAndStop((this.level - 1) % 3 + 1);
- this.howFar = 0;
- smashing.Viewport.reset();
- this.oBuildings.reset(this.level);
- this.oPlayer.reset();
- this.oPlayer.render();
- this.mcGround.y = BuildingHandler.floor - 200;
- this.cTime = this.startTime;
- this.oCitizens.reset();
- this.oCitizens.setLevel(this.level);
- this.oGerms.reset();
- this.moveView = this.moveViewGame;
- this.endCheck = this.endCheckGame;
- this.cTime = this.startTime;
- this.cTimeRatio = 0;
- this.nTime = Math.max(this.nFullTime - this.nTimeDec * this.level,this.nLowerTimeLimit);
- this.nDistRatio = 0;
- this.update(0);
- }
- function endLevelPrep()
- {
- this.endCheck = this.endCheckEnd;
- this.oBuildings.addHome();
- }
- function endLevel()
- {
- _global.mcRoot.mcMusic.oSound.stop();
- _global.mcRoot.mcMenu.nLevel = this.level;
- if(this.cTimeRatio <= 0)
- {
- _global.mcRoot.mcMenu.show("noTime");
- }
- else if(this.level >= 3)
- {
- var _loc4_ = this.nDistRatio - this.cTimeRatio;
- var _loc3_ = Math.floor(_loc4_ * this.timeBonus);
- smashing.Menu.target.timeBonus = _loc3_;
- smashing.Menu.target.oldScore = this.score;
- this.score += _loc3_;
- smashing.Menu.target.newScore = this.score;
- this.endGame();
- }
- else
- {
- _loc4_ = this.nDistRatio - this.cTimeRatio;
- _loc3_ = Math.floor(_loc4_ * this.timeBonus);
- smashing.Menu.target.timeBonus = _loc3_;
- smashing.Menu.target.oldScore = this.score;
- this.score += _loc3_;
- smashing.Menu.target.newScore = this.score;
- _global.mcRoot.mcMenu.show("levelEnd");
- this.level = this.level + 1;
- }
- }
- function endGame()
- {
- _global.mcRoot.finalScore = this.score;
- _global.mcRoot.mcMenu.show("gameEnd");
- }
- function reset()
- {
- this.cTime = this.startTime;
- }
- function moveViewGame(nElapsed)
- {
- smashing.Viewport.y = this.oPlayer.y;
- var _loc4_ = BuildingHandler.floor - smashing.Viewport.halfHeight + 15;
- if(smashing.Viewport.y > _loc4_)
- {
- smashing.Viewport.y = _loc4_;
- }
- else
- {
- var _loc5_ = BuildingHandler.ceiling + smashing.Viewport.halfHeight;
- if(smashing.Viewport.y < _loc5_)
- {
- smashing.Viewport.y = _loc5_;
- }
- }
- var _loc3_ = this.oPlayer.x + this.playerOffset;
- if(_loc3_ > smashing.Viewport.startX)
- {
- smashing.Viewport.x = _loc3_;
- }
- else
- {
- smashing.Viewport.x = smashing.Viewport.startX;
- }
- var _loc2_ = BuildingHandler.homeLimit;
- if(_loc2_ != undefined)
- {
- if(smashing.Viewport.x > _loc2_)
- {
- smashing.Viewport.x = _loc2_;
- }
- }
- if(smashing.Viewport.x > this.howFar)
- {
- this.howFar = smashing.Viewport.x;
- }
- }
- function moveViewEnd(nElapsed)
- {
- smashing.Viewport.y = this.oPlayer.y;
- var _loc4_ = BuildingHandler.floor - smashing.Viewport.halfHeight + 15;
- if(smashing.Viewport.y > _loc4_)
- {
- smashing.Viewport.y = _loc4_;
- }
- else
- {
- var _loc5_ = BuildingHandler.ceiling + smashing.Viewport.halfHeight;
- if(smashing.Viewport.y < _loc5_)
- {
- smashing.Viewport.y = _loc5_;
- }
- }
- var _loc3_ = this.oPlayer.x + this.playerOffset;
- if(_loc3_ - smashing.Viewport.x > 0)
- {
- smashing.Viewport.x = _loc3_;
- }
- var _loc2_ = BuildingHandler.home;
- var _loc6_ = _loc2_.x + _loc2_._width - smashing.Viewport.halfWidth;
- if(smashing.Viewport.x > _loc6_)
- {
- smashing.Viewport.x = _loc6_;
- }
- }
- function endCheckGame()
- {
- if(this.cTimeRatio <= 0)
- {
- this.endLevel();
- }
- if(smashing.Viewport.x >= this.nDist)
- {
- this.endLevelPrep();
- }
- }
- function endCheckEnd()
- {
- if(this.cTimeRatio <= 0)
- {
- this.endLevel();
- }
- if(this.oPlayer.hitTest(BuildingHandler.home.mcHitArea))
- {
- if(this.oPlayer.aCritters.length >= this.totalCritters)
- {
- this.endLevel();
- }
- else if(_global.mcRoot.mcFillBook._currentframe == 1)
- {
- _global.mcRoot.mcFillBook.bPlayed = true;
- _global.mcRoot.mcFillBook.gotoAndPlay(2);
- }
- }
- }
- static function addScore(nScore)
- {
- DiegoWorld.target.score += nScore;
- }
- }
-